<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for c:\program files\python26\lib\threading</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    var hide = "hide_"+cls;
    if (btn.hasClass(hide)) {
        $("#source ."+cls).removeClass(hide);
        btn.removeClass(hide);
    }
    else {
        $("#source ."+cls).addClass(hide);
        btn.addClass(hide);
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>c:\program files\python26\lib\threading</b> :
            <span class='pc_cov'>22%</span>
        </h1>
        <h2 class='stats'>
            576 statements
            <span class='run hide_run' onclick='toggle_lines(this, "run")'>125 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>451 missing</span>
            
                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>18 partial</span>
            
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='pln'>2</p>
<p class='stm mis'>3</p>
<p class='pln'>4</p>
<p class='stm mis'>5</p>
<p class='stm mis'>6</p>
<p class='stm mis'>7</p>
<p class='stm mis'>8</p>
<p class='stm mis'>9</p>
<p class='pln'>10</p>
<p class='stm mis'>11</p>
<p class='pln'>12</p>
<p class='stm mis'>13</p>
<p class='stm mis'>14</p>
<p class='stm mis'>15</p>
<p class='stm mis'>16</p>
<p class='pln'>17</p>
<p class='pln'>18</p>
<p class='pln'>19</p>
<p class='pln'>20</p>
<p class='pln'>21</p>
<p class='pln'>22</p>
<p class='pln'>23</p>
<p class='pln'>24</p>
<p class='pln'>25</p>
<p class='pln'>26</p>
<p class='pln'>27</p>
<p class='pln'>28</p>
<p class='pln'>29</p>
<p class='stm mis'>30</p>
<p class='pln'>31</p>
<p class='pln'>32</p>
<p class='pln'>33</p>
<p class='pln'>34</p>
<p class='stm mis'>35</p>
<p class='stm mis'>36</p>
<p class='stm mis'>37</p>
<p class='stm mis'>38</p>
<p class='stm mis'>39</p>
<p class='pln'>40</p>
<p class='pln'>41</p>
<p class='pln'>42</p>
<p class='pln'>43</p>
<p class='stm mis'>44</p>
<p class='pln'>45</p>
<p class='pln'>46</p>
<p class='pln'>47</p>
<p class='pln'>48</p>
<p class='pln'>49</p>
<p class='pln'>50</p>
<p class='pln'>51</p>
<p class='pln'>52</p>
<p class='stm mis'>53</p>
<p class='pln'>54</p>
<p class='pln'>55</p>
<p class='pln'>56</p>
<p class='stm mis'>57</p>
<p class='pln'>58</p>
<p class='stm mis'>59</p>
<p class='stm par run hide_run'>60</p>
<p class='stm run hide_run'>61</p>
<p class='stm run hide_run'>62</p>
<p class='pln'>63</p>
<p class='stm mis'>64</p>
<p class='stm par run hide_run'>65</p>
<p class='stm mis'>66</p>
<p class='stm mis'>67</p>
<p class='pln'>68</p>
<p class='stm mis'>69</p>
<p class='pln'>70</p>
<p class='pln'>71</p>
<p class='pln'>72</p>
<p class='pln'>73</p>
<p class='pln'>74</p>
<p class='pln'>75</p>
<p class='pln'>76</p>
<p class='pln'>77</p>
<p class='pln'>78</p>
<p class='pln'>79</p>
<p class='pln'>80</p>
<p class='stm mis'>81</p>
<p class='stm mis'>82</p>
<p class='pln'>83</p>
<p class='stm mis'>84</p>
<p class='pln'>85</p>
<p class='stm mis'>86</p>
<p class='pln'>87</p>
<p class='stm mis'>88</p>
<p class='pln'>89</p>
<p class='stm run hide_run'>90</p>
<p class='pln'>91</p>
<p class='pln'>92</p>
<p class='pln'>93</p>
<p class='stm mis'>94</p>
<p class='pln'>95</p>
<p class='stm mis'>96</p>
<p class='stm run hide_run'>97</p>
<p class='pln'>98</p>
<p class='stm mis'>99</p>
<p class='pln'>100</p>
<p class='stm mis'>101</p>
<p class='stm run hide_run'>102</p>
<p class='stm run hide_run'>103</p>
<p class='stm run hide_run'>104</p>
<p class='stm run hide_run'>105</p>
<p class='pln'>106</p>
<p class='stm mis'>107</p>
<p class='stm mis'>108</p>
<p class='stm mis'>109</p>
<p class='pln'>110</p>
<p class='pln'>111</p>
<p class='pln'>112</p>
<p class='pln'>113</p>
<p class='stm mis'>114</p>
<p class='stm run hide_run'>115</p>
<p class='stm par run hide_run'>116</p>
<p class='stm mis'>117</p>
<p class='pln'>118</p>
<p class='stm mis'>119</p>
<p class='stm mis'>120</p>
<p class='stm run hide_run'>121</p>
<p class='stm par run hide_run'>122</p>
<p class='stm run hide_run'>123</p>
<p class='stm run hide_run'>124</p>
<p class='pln'>125</p>
<p class='stm run hide_run'>126</p>
<p class='pln'>127</p>
<p class='pln'>128</p>
<p class='stm mis'>129</p>
<p class='stm run hide_run'>130</p>
<p class='pln'>131</p>
<p class='stm mis'>132</p>
<p class='pln'>133</p>
<p class='stm mis'>134</p>
<p class='stm par run hide_run'>135</p>
<p class='stm mis'>136</p>
<p class='stm run hide_run'>137</p>
<p class='stm par run hide_run'>138</p>
<p class='stm run hide_run'>139</p>
<p class='stm run hide_run'>140</p>
<p class='pln'>141</p>
<p class='stm run hide_run'>142</p>
<p class='pln'>143</p>
<p class='pln'>144</p>
<p class='stm mis'>145</p>
<p class='pln'>146</p>
<p class='stm mis'>147</p>
<p class='stm mis'>148</p>
<p class='pln'>149</p>
<p class='pln'>150</p>
<p class='pln'>151</p>
<p class='stm mis'>152</p>
<p class='stm mis'>153</p>
<p class='stm mis'>154</p>
<p class='stm mis'>155</p>
<p class='stm mis'>156</p>
<p class='pln'>157</p>
<p class='stm mis'>158</p>
<p class='pln'>159</p>
<p class='stm mis'>160</p>
<p class='pln'>161</p>
<p class='stm mis'>162</p>
<p class='stm mis'>163</p>
<p class='stm mis'>164</p>
<p class='stm mis'>165</p>
<p class='stm mis'>166</p>
<p class='stm mis'>167</p>
<p class='stm mis'>168</p>
<p class='pln'>169</p>
<p class='stm mis'>170</p>
<p class='stm mis'>171</p>
<p class='pln'>172</p>
<p class='pln'>173</p>
<p class='stm mis'>174</p>
<p class='stm run hide_run'>175</p>
<p class='pln'>176</p>
<p class='stm mis'>177</p>
<p class='pln'>178</p>
<p class='stm mis'>179</p>
<p class='stm run hide_run'>180</p>
<p class='stm par run hide_run'>181</p>
<p class='stm mis'>182</p>
<p class='stm run hide_run'>183</p>
<p class='pln'>184</p>
<p class='stm run hide_run'>185</p>
<p class='stm run hide_run'>186</p>
<p class='pln'>187</p>
<p class='pln'>188</p>
<p class='pln'>189</p>
<p class='stm run hide_run'>190</p>
<p class='stm run hide_run'>191</p>
<p class='stm run hide_run'>192</p>
<p class='stm run hide_run'>193</p>
<p class='stm run hide_run'>194</p>
<p class='stm run hide_run'>195</p>
<p class='stm run hide_run'>196</p>
<p class='stm run hide_run'>197</p>
<p class='stm run hide_run'>198</p>
<p class='stm run hide_run'>199</p>
<p class='stm run hide_run'>200</p>
<p class='stm run hide_run'>201</p>
<p class='stm run hide_run'>202</p>
<p class='pln'>203</p>
<p class='stm mis'>204</p>
<p class='stm mis'>205</p>
<p class='pln'>206</p>
<p class='stm mis'>207</p>
<p class='stm mis'>208</p>
<p class='pln'>209</p>
<p class='stm mis'>210</p>
<p class='stm mis'>211</p>
<p class='pln'>212</p>
<p class='stm mis'>213</p>
<p class='stm run hide_run'>214</p>
<p class='pln'>215</p>
<p class='stm mis'>216</p>
<p class='stm run hide_run'>217</p>
<p class='pln'>218</p>
<p class='stm mis'>219</p>
<p class='pln'>220</p>
<p class='pln'>221</p>
<p class='stm par run hide_run'>222</p>
<p class='stm mis'>223</p>
<p class='stm mis'>224</p>
<p class='pln'>225</p>
<p class='stm run hide_run'>226</p>
<p class='pln'>227</p>
<p class='stm mis'>228</p>
<p class='stm par run hide_run'>229</p>
<p class='stm mis'>230</p>
<p class='stm run hide_run'>231</p>
<p class='stm run hide_run'>232</p>
<p class='stm run hide_run'>233</p>
<p class='stm run hide_run'>234</p>
<p class='stm run hide_run'>235</p>
<p class='stm par run hide_run'>236</p>
<p class='stm run hide_run'>237</p>
<p class='pln'>238</p>
<p class='stm run hide_run'>239</p>
<p class='pln'>240</p>
<p class='pln'>241</p>
<p class='pln'>242</p>
<p class='pln'>243</p>
<p class='pln'>244</p>
<p class='pln'>245</p>
<p class='stm mis'>246</p>
<p class='stm mis'>247</p>
<p class='stm mis'>248</p>
<p class='stm mis'>249</p>
<p class='stm mis'>250</p>
<p class='stm mis'>251</p>
<p class='stm mis'>252</p>
<p class='stm mis'>253</p>
<p class='stm mis'>254</p>
<p class='stm mis'>255</p>
<p class='stm mis'>256</p>
<p class='stm mis'>257</p>
<p class='pln'>258</p>
<p class='stm mis'>259</p>
<p class='stm mis'>260</p>
<p class='stm mis'>261</p>
<p class='stm mis'>262</p>
<p class='stm mis'>263</p>
<p class='pln'>264</p>
<p class='pln'>265</p>
<p class='stm mis'>266</p>
<p class='pln'>267</p>
<p class='stm run hide_run'>268</p>
<p class='pln'>269</p>
<p class='stm mis'>270</p>
<p class='stm par run hide_run'>271</p>
<p class='stm mis'>272</p>
<p class='stm run hide_run'>273</p>
<p class='stm run hide_run'>274</p>
<p class='stm run hide_run'>275</p>
<p class='pln'>276</p>
<p class='stm run hide_run'>277</p>
<p class='stm run hide_run'>278</p>
<p class='stm run hide_run'>279</p>
<p class='pln'>280</p>
<p class='stm run hide_run'>281</p>
<p class='stm run hide_run'>282</p>
<p class='stm run hide_run'>283</p>
<p class='stm run hide_run'>284</p>
<p class='stm mis'>285</p>
<p class='stm mis'>286</p>
<p class='pln'>287</p>
<p class='stm mis'>288</p>
<p class='stm run hide_run'>289</p>
<p class='pln'>290</p>
<p class='stm mis'>291</p>
<p class='pln'>292</p>
<p class='pln'>293</p>
<p class='stm mis'>294</p>
<p class='stm mis'>295</p>
<p class='pln'>296</p>
<p class='stm mis'>297</p>
<p class='pln'>298</p>
<p class='pln'>299</p>
<p class='pln'>300</p>
<p class='stm mis'>301</p>
<p class='stm mis'>302</p>
<p class='stm mis'>303</p>
<p class='stm mis'>304</p>
<p class='stm mis'>305</p>
<p class='stm mis'>306</p>
<p class='pln'>307</p>
<p class='stm mis'>308</p>
<p class='stm mis'>309</p>
<p class='stm mis'>310</p>
<p class='stm mis'>311</p>
<p class='stm mis'>312</p>
<p class='stm mis'>313</p>
<p class='pln'>314</p>
<p class='stm mis'>315</p>
<p class='pln'>316</p>
<p class='stm mis'>317</p>
<p class='pln'>318</p>
<p class='stm mis'>319</p>
<p class='pln'>320</p>
<p class='stm mis'>321</p>
<p class='pln'>322</p>
<p class='stm mis'>323</p>
<p class='stm mis'>324</p>
<p class='stm mis'>325</p>
<p class='pln'>326</p>
<p class='stm mis'>327</p>
<p class='pln'>328</p>
<p class='stm mis'>329</p>
<p class='stm mis'>330</p>
<p class='stm mis'>331</p>
<p class='pln'>332</p>
<p class='stm mis'>333</p>
<p class='pln'>334</p>
<p class='stm mis'>335</p>
<p class='stm mis'>336</p>
<p class='pln'>337</p>
<p class='stm mis'>338</p>
<p class='stm mis'>339</p>
<p class='pln'>340</p>
<p class='pln'>341</p>
<p class='stm mis'>342</p>
<p class='stm mis'>343</p>
<p class='pln'>344</p>
<p class='stm mis'>345</p>
<p class='pln'>346</p>
<p class='stm mis'>347</p>
<p class='stm mis'>348</p>
<p class='stm mis'>349</p>
<p class='pln'>350</p>
<p class='stm mis'>351</p>
<p class='stm mis'>352</p>
<p class='stm mis'>353</p>
<p class='stm mis'>354</p>
<p class='pln'>355</p>
<p class='pln'>356</p>
<p class='stm mis'>357</p>
<p class='stm run hide_run'>358</p>
<p class='pln'>359</p>
<p class='stm mis'>360</p>
<p class='pln'>361</p>
<p class='pln'>362</p>
<p class='pln'>363</p>
<p class='stm mis'>364</p>
<p class='stm run hide_run'>365</p>
<p class='stm run hide_run'>366</p>
<p class='stm run hide_run'>367</p>
<p class='pln'>368</p>
<p class='stm mis'>369</p>
<p class='stm run hide_run'>370</p>
<p class='pln'>371</p>
<p class='stm mis'>372</p>
<p class='pln'>373</p>
<p class='stm mis'>374</p>
<p class='stm mis'>375</p>
<p class='stm mis'>376</p>
<p class='stm mis'>377</p>
<p class='stm mis'>378</p>
<p class='pln'>379</p>
<p class='stm mis'>380</p>
<p class='pln'>381</p>
<p class='stm mis'>382</p>
<p class='stm mis'>383</p>
<p class='stm mis'>384</p>
<p class='stm mis'>385</p>
<p class='pln'>386</p>
<p class='stm mis'>387</p>
<p class='pln'>388</p>
<p class='stm mis'>389</p>
<p class='stm run hide_run'>390</p>
<p class='stm run hide_run'>391</p>
<p class='stm run hide_run'>392</p>
<p class='stm run hide_run'>393</p>
<p class='pln'>394</p>
<p class='stm run hide_run'>395</p>
<p class='pln'>396</p>
<p class='pln'>397</p>
<p class='stm mis'>398</p>
<p class='stm mis'>399</p>
<p class='pln'>400</p>
<p class='stm run hide_run'>401</p>
<p class='stm run hide_run'>402</p>
<p class='pln'>403</p>
<p class='pln'>404</p>
<p class='stm mis'>405</p>
<p class='stm mis'>406</p>
<p class='stm mis'>407</p>
<p class='pln'>408</p>
<p class='pln'>409</p>
<p class='pln'>410</p>
<p class='pln'>411</p>
<p class='stm mis'>412</p>
<p class='pln'>413</p>
<p class='stm mis'>414</p>
<p class='pln'>415</p>
<p class='pln'>416</p>
<p class='pln'>417</p>
<p class='pln'>418</p>
<p class='stm mis'>419</p>
<p class='pln'>420</p>
<p class='pln'>421</p>
<p class='stm mis'>422</p>
<p class='pln'>423</p>
<p class='stm mis'>424</p>
<p class='pln'>425</p>
<p class='stm run hide_run'>426</p>
<p class='stm run hide_run'>427</p>
<p class='stm par run hide_run'>428</p>
<p class='stm run hide_run'>429</p>
<p class='stm run hide_run'>430</p>
<p class='stm run hide_run'>431</p>
<p class='stm run hide_run'>432</p>
<p class='stm run hide_run'>433</p>
<p class='stm run hide_run'>434</p>
<p class='stm run hide_run'>435</p>
<p class='stm run hide_run'>436</p>
<p class='stm run hide_run'>437</p>
<p class='stm run hide_run'>438</p>
<p class='stm run hide_run'>439</p>
<p class='pln'>440</p>
<p class='pln'>441</p>
<p class='stm run hide_run'>442</p>
<p class='pln'>443</p>
<p class='stm mis'>444</p>
<p class='pln'>445</p>
<p class='stm run hide_run'>446</p>
<p class='pln'>447</p>
<p class='stm mis'>448</p>
<p class='stm mis'>449</p>
<p class='stm mis'>450</p>
<p class='stm mis'>451</p>
<p class='stm mis'>452</p>
<p class='stm mis'>453</p>
<p class='stm mis'>454</p>
<p class='stm mis'>455</p>
<p class='stm mis'>456</p>
<p class='stm mis'>457</p>
<p class='stm mis'>458</p>
<p class='stm mis'>459</p>
<p class='pln'>460</p>
<p class='stm mis'>461</p>
<p class='stm par run hide_run'>462</p>
<p class='stm mis'>463</p>
<p class='stm par run hide_run'>464</p>
<p class='stm mis'>465</p>
<p class='pln'>466</p>
<p class='stm run hide_run'>467</p>
<p class='stm run hide_run'>468</p>
<p class='stm run hide_run'>469</p>
<p class='stm run hide_run'>470</p>
<p class='stm run hide_run'>471</p>
<p class='stm run hide_run'>472</p>
<p class='pln'>473</p>
<p class='stm mis'>474</p>
<p class='stm mis'>475</p>
<p class='stm mis'>476</p>
<p class='stm mis'>477</p>
<p class='pln'>478</p>
<p class='pln'>479</p>
<p class='pln'>480</p>
<p class='stm mis'>481</p>
<p class='pln'>482</p>
<p class='stm mis'>483</p>
<p class='pln'>484</p>
<p class='pln'>485</p>
<p class='pln'>486</p>
<p class='pln'>487</p>
<p class='pln'>488</p>
<p class='pln'>489</p>
<p class='pln'>490</p>
<p class='pln'>491</p>
<p class='pln'>492</p>
<p class='pln'>493</p>
<p class='pln'>494</p>
<p class='pln'>495</p>
<p class='stm mis'>496</p>
<p class='stm mis'>497</p>
<p class='stm mis'>498</p>
<p class='stm mis'>499</p>
<p class='stm mis'>500</p>
<p class='stm mis'>501</p>
<p class='pln'>502</p>
<p class='stm mis'>503</p>
<p class='stm mis'>504</p>
<p class='pln'>505</p>
<p class='stm mis'>506</p>
<p class='stm mis'>507</p>
<p class='stm mis'>508</p>
<p class='stm mis'>509</p>
<p class='stm mis'>510</p>
<p class='stm mis'>511</p>
<p class='stm mis'>512</p>
<p class='stm mis'>513</p>
<p class='pln'>514</p>
<p class='stm mis'>515</p>
<p class='pln'>516</p>
<p class='stm mis'>517</p>
<p class='stm mis'>518</p>
<p class='stm mis'>519</p>
<p class='stm mis'>520</p>
<p class='stm mis'>521</p>
<p class='stm mis'>522</p>
<p class='pln'>523</p>
<p class='stm mis'>524</p>
<p class='stm mis'>525</p>
<p class='stm mis'>526</p>
<p class='pln'>527</p>
<p class='stm mis'>528</p>
<p class='stm mis'>529</p>
<p class='pln'>530</p>
<p class='stm mis'>531</p>
<p class='pln'>532</p>
<p class='pln'>533</p>
<p class='pln'>534</p>
<p class='pln'>535</p>
<p class='stm mis'>536</p>
<p class='stm mis'>537</p>
<p class='pln'>538</p>
<p class='pln'>539</p>
<p class='pln'>540</p>
<p class='pln'>541</p>
<p class='pln'>542</p>
<p class='stm mis'>543</p>
<p class='stm mis'>544</p>
<p class='stm mis'>545</p>
<p class='pln'>546</p>
<p class='pln'>547</p>
<p class='stm mis'>548</p>
<p class='pln'>549</p>
<p class='stm mis'>550</p>
<p class='stm mis'>551</p>
<p class='pln'>552</p>
<p class='pln'>553</p>
<p class='pln'>554</p>
<p class='pln'>555</p>
<p class='stm mis'>556</p>
<p class='stm mis'>557</p>
<p class='pln'>558</p>
<p class='pln'>559</p>
<p class='pln'>560</p>
<p class='stm mis'>561</p>
<p class='pln'>562</p>
<p class='pln'>563</p>
<p class='stm mis'>564</p>
<p class='pln'>565</p>
<p class='pln'>566</p>
<p class='pln'>567</p>
<p class='pln'>568</p>
<p class='pln'>569</p>
<p class='stm mis'>570</p>
<p class='pln'>571</p>
<p class='stm mis'>572</p>
<p class='stm mis'>573</p>
<p class='stm mis'>574</p>
<p class='pln'>575</p>
<p class='pln'>576</p>
<p class='stm mis'>577</p>
<p class='stm mis'>578</p>
<p class='stm mis'>579</p>
<p class='pln'>580</p>
<p class='stm mis'>581</p>
<p class='stm run hide_run'>582</p>
<p class='stm run hide_run'>583</p>
<p class='stm run hide_run'>584</p>
<p class='stm run hide_run'>585</p>
<p class='pln'>586</p>
<p class='stm mis'>587</p>
<p class='pln'>588</p>
<p class='pln'>589</p>
<p class='pln'>590</p>
<p class='pln'>591</p>
<p class='pln'>592</p>
<p class='pln'>593</p>
<p class='pln'>594</p>
<p class='pln'>595</p>
<p class='pln'>596</p>
<p class='pln'>597</p>
<p class='pln'>598</p>
<p class='pln'>599</p>
<p class='pln'>600</p>
<p class='pln'>601</p>
<p class='pln'>602</p>
<p class='pln'>603</p>
<p class='pln'>604</p>
<p class='pln'>605</p>
<p class='pln'>606</p>
<p class='pln'>607</p>
<p class='pln'>608</p>
<p class='pln'>609</p>
<p class='pln'>610</p>
<p class='stm mis'>611</p>
<p class='stm mis'>612</p>
<p class='stm mis'>613</p>
<p class='pln'>614</p>
<p class='pln'>615</p>
<p class='pln'>616</p>
<p class='pln'>617</p>
<p class='stm mis'>618</p>
<p class='stm mis'>619</p>
<p class='stm mis'>620</p>
<p class='pln'>621</p>
<p class='stm mis'>622</p>
<p class='stm par run hide_run'>623</p>
<p class='stm mis'>624</p>
<p class='stm par run hide_run'>625</p>
<p class='stm mis'>626</p>
<p class='stm par run hide_run'>627</p>
<p class='stm mis'>628</p>
<p class='pln'>629</p>
<p class='pln'>630</p>
<p class='stm run hide_run'>631</p>
<p class='stm run hide_run'>632</p>
<p class='stm run hide_run'>633</p>
<p class='stm run hide_run'>634</p>
<p class='stm par run hide_run'>635</p>
<p class='stm run hide_run'>636</p>
<p class='stm run hide_run'>637</p>
<p class='pln'>638</p>
<p class='stm run hide_run'>639</p>
<p class='pln'>640</p>
<p class='stm mis'>641</p>
<p class='stm mis'>642</p>
<p class='stm mis'>643</p>
<p class='stm mis'>644</p>
<p class='pln'>645</p>
<p class='stm mis'>646</p>
<p class='stm mis'>647</p>
<p class='stm mis'>648</p>
<p class='pln'>649</p>
<p class='pln'>650</p>
<p class='stm mis'>651</p>
<p class='pln'>652</p>
<p class='stm run hide_run'>653</p>
<p class='pln'>654</p>
<p class='stm mis'>655</p>
<p class='pln'>656</p>
<p class='stm mis'>657</p>
<p class='stm mis'>658</p>
<p class='pln'>659</p>
<p class='stm mis'>660</p>
<p class='pln'>661</p>
<p class='stm mis'>662</p>
<p class='stm mis'>663</p>
<p class='pln'>664</p>
<p class='stm mis'>665</p>
<p class='pln'>666</p>
<p class='stm mis'>667</p>
<p class='stm mis'>668</p>
<p class='pln'>669</p>
<p class='stm mis'>670</p>
<p class='stm mis'>671</p>
<p class='stm mis'>672</p>
<p class='pln'>673</p>
<p class='stm mis'>674</p>
<p class='pln'>675</p>
<p class='stm mis'>676</p>
<p class='pln'>677</p>
<p class='stm run hide_run'>678</p>
<p class='stm run hide_run'>679</p>
<p class='pln'>680</p>
<p class='stm mis'>681</p>
<p class='pln'>682</p>
<p class='stm mis'>683</p>
<p class='stm mis'>684</p>
<p class='stm mis'>685</p>
<p class='stm mis'>686</p>
<p class='stm mis'>687</p>
<p class='pln'>688</p>
<p class='stm mis'>689</p>
<p class='stm mis'>690</p>
<p class='pln'>691</p>
<p class='stm mis'>692</p>
<p class='stm mis'>693</p>
<p class='pln'>694</p>
<p class='stm mis'>695</p>
<p class='stm mis'>696</p>
<p class='pln'>697</p>
<p class='stm mis'>698</p>
<p class='stm mis'>699</p>
<p class='pln'>700</p>
<p class='pln'>701</p>
<p class='pln'>702</p>
<p class='stm mis'>703</p>
<p class='stm mis'>704</p>
<p class='pln'>705</p>
<p class='stm mis'>706</p>
<p class='pln'>707</p>
<p class='pln'>708</p>
<p class='pln'>709</p>
<p class='pln'>710</p>
<p class='pln'>711</p>
<p class='pln'>712</p>
<p class='pln'>713</p>
<p class='stm mis'>714</p>
<p class='stm mis'>715</p>
<p class='stm mis'>716</p>
<p class='stm mis'>717</p>
<p class='stm mis'>718</p>
<p class='stm mis'>719</p>
<p class='stm mis'>720</p>
<p class='pln'>721</p>
<p class='stm mis'>722</p>
<p class='pln'>723</p>
<p class='stm mis'>724</p>
<p class='pln'>725</p>
<p class='stm mis'>726</p>
<p class='stm mis'>727</p>
<p class='stm mis'>728</p>
<p class='stm mis'>729</p>
<p class='stm mis'>730</p>
<p class='pln'>731</p>
<p class='pln'>732</p>
<p class='pln'>733</p>
<p class='pln'>734</p>
<p class='stm mis'>735</p>
<p class='pln'>736</p>
<p class='stm mis'>737</p>
<p class='stm mis'>738</p>
<p class='stm mis'>739</p>
<p class='stm mis'>740</p>
<p class='stm mis'>741</p>
<p class='stm mis'>742</p>
<p class='stm mis'>743</p>
<p class='pln'>744</p>
<p class='stm mis'>745</p>
<p class='stm mis'>746</p>
<p class='pln'>747</p>
<p class='stm mis'>748</p>
<p class='stm mis'>749</p>
<p class='stm mis'>750</p>
<p class='stm mis'>751</p>
<p class='pln'>752</p>
<p class='stm mis'>753</p>
<p class='stm mis'>754</p>
<p class='stm mis'>755</p>
<p class='stm mis'>756</p>
<p class='pln'>757</p>
<p class='stm mis'>758</p>
<p class='stm mis'>759</p>
<p class='pln'>760</p>
<p class='stm mis'>761</p>
<p class='stm mis'>762</p>
<p class='stm mis'>763</p>
<p class='stm mis'>764</p>
<p class='stm mis'>765</p>
<p class='pln'>766</p>
<p class='pln'>767</p>
<p class='pln'>768</p>
<p class='pln'>769</p>
<p class='pln'>770</p>
<p class='pln'>771</p>
<p class='pln'>772</p>
<p class='pln'>773</p>
<p class='pln'>774</p>
<p class='pln'>775</p>
<p class='stm mis'>776</p>
<p class='pln'>777</p>
<p class='stm mis'>778</p>
<p class='stm mis'>779</p>
<p class='pln'>780</p>
<p class='pln'>781</p>
<p class='pln'>782</p>
<p class='pln'>783</p>
<p class='stm mis'>784</p>
<p class='pln'>785</p>
<p class='stm mis'>786</p>
<p class='stm mis'>787</p>
<p class='stm mis'>788</p>
<p class='stm mis'>789</p>
<p class='stm mis'>790</p>
<p class='pln'>791</p>
<p class='stm mis'>792</p>
<p class='stm mis'>793</p>
<p class='pln'>794</p>
<p class='stm mis'>795</p>
<p class='stm mis'>796</p>
<p class='pln'>797</p>
<p class='pln'>798</p>
<p class='pln'>799</p>
<p class='pln'>800</p>
<p class='stm mis'>801</p>
<p class='stm run hide_run'>802</p>
<p class='stm run hide_run'>803</p>
<p class='stm mis'>804</p>
<p class='pln'>805</p>
<p class='stm mis'>806</p>
<p class='pln'>807</p>
<p class='stm mis'>808</p>
<p class='pln'>809</p>
<p class='stm mis'>810</p>
<p class='stm mis'>811</p>
<p class='stm mis'>812</p>
<p class='stm mis'>813</p>
<p class='stm mis'>814</p>
<p class='pln'>815</p>
<p class='stm mis'>816</p>
<p class='pln'>817</p>
<p class='stm mis'>818</p>
<p class='stm mis'>819</p>
<p class='stm mis'>820</p>
<p class='stm mis'>821</p>
<p class='stm mis'>822</p>
<p class='pln'>823</p>
<p class='stm mis'>824</p>
<p class='pln'>825</p>
<p class='pln'>826</p>
<p class='pln'>827</p>
<p class='pln'>828</p>
<p class='pln'>829</p>
<p class='stm mis'>830</p>
<p class='pln'>831</p>
<p class='pln'>832</p>
<p class='pln'>833</p>
<p class='pln'>834</p>
<p class='stm mis'>835</p>
<p class='stm mis'>836</p>
<p class='stm mis'>837</p>
<p class='stm mis'>838</p>
<p class='pln'>839</p>
<p class='pln'>840</p>
<p class='stm mis'>841</p>
<p class='pln'>842</p>
<p class='pln'>843</p>
<p class='pln'>844</p>
<p class='pln'>845</p>
<p class='pln'>846</p>
<p class='pln'>847</p>
<p class='pln'>848</p>
<p class='stm mis'>849</p>
<p class='pln'>850</p>
<p class='pln'>851</p>
<p class='stm mis'>852</p>
<p class='stm mis'>853</p>
<p class='stm mis'>854</p>
<p class='stm mis'>855</p>
<p class='stm mis'>856</p>
<p class='pln'>857</p>
<p class='pln'>858</p>
<p class='stm mis'>859</p>
<p class='stm mis'>860</p>
<p class='stm mis'>861</p>
<p class='pln'>862</p>
<p class='pln'>863</p>
<p class='pln'>864</p>
<p class='pln'>865</p>
<p class='pln'>866</p>
<p class='stm mis'>867</p>
<p class='pln'>868</p>
<p class='stm mis'>869</p>
<p class='stm mis'>870</p>
<p class='stm mis'>871</p>
<p class='stm mis'>872</p>
<p class='pln'>873</p>
<p class='pln'>874</p>
<p class='pln'>875</p>
<p class='pln'>876</p>
<p class='stm mis'>877</p>
<p class='pln'>878</p>
<p class='stm mis'>879</p>
<p class='pln'>880</p>
<p class='stm mis'>881</p>
<p class='stm mis'>882</p>
<p class='stm mis'>883</p>
<p class='stm mis'>884</p>
<p class='stm mis'>885</p>
<p class='stm mis'>886</p>
<p class='stm mis'>887</p>
<p class='pln'>888</p>
<p class='stm mis'>889</p>
<p class='stm mis'>890</p>
<p class='stm mis'>891</p>
<p class='stm mis'>892</p>
<p class='stm mis'>893</p>
<p class='stm mis'>894</p>
<p class='stm mis'>895</p>
<p class='pln'>896</p>
<p class='stm mis'>897</p>
<p class='stm mis'>898</p>
<p class='pln'>899</p>
<p class='stm mis'>900</p>
<p class='stm mis'>901</p>
<p class='stm mis'>902</p>
<p class='stm mis'>903</p>
<p class='stm mis'>904</p>
<p class='stm mis'>905</p>
<p class='stm mis'>906</p>
<p class='stm mis'>907</p>
<p class='stm mis'>908</p>
<p class='stm mis'>909</p>
<p class='pln'>910</p>
<p class='stm mis'>911</p>
<p class='pln'>912</p>
<p class='stm mis'>913</p>
<p class='stm mis'>914</p>
<p class='stm mis'>915</p>
<p class='stm mis'>916</p>
<p class='pln'>917</p>
<p class='stm mis'>918</p>
<p class='stm mis'>919</p>
<p class='stm mis'>920</p>
<p class='stm mis'>921</p>
<p class='stm mis'>922</p>
<p class='stm mis'>923</p>
<p class='stm mis'>924</p>
<p class='pln'>925</p>
<p class='pln'>926</p>
<p class='stm mis'>927</p>
<p class='pln'>928</p>
<p class='stm mis'>929</p>
<p class='stm mis'>930</p>
<p class='stm mis'>931</p>
<p class='stm mis'>932</p>
<p class='pln'>933</p>
<p class='stm mis'>934</p>
<p class='stm mis'>935</p>
<p class='stm mis'>936</p>
<p class='stm mis'>937</p>
<p class='stm mis'>938</p>
<p class='pln'>939</p>
<p class='stm mis'>940</p>
<p class='stm mis'>941</p>
<p class='stm mis'>942</p>
<p class='pln'>943</p>
<p class='stm mis'>944</p>
<p class='stm mis'>945</p>
<p class='stm mis'>946</p>
<p class='stm mis'>947</p>
<p class='stm mis'>948</p>
<p class='stm mis'>949</p>
<p class='stm mis'>950</p>
<p class='stm mis'>951</p>
<p class='stm mis'>952</p>
<p class='stm mis'>953</p>
<p class='stm mis'>954</p>
<p class='stm mis'>955</p>
<p class='stm mis'>956</p>
<p class='stm mis'>957</p>
<p class='pln'>958</p>
<p class='stm mis'>959</p>
<p class='stm mis'>960</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'><span class='str'>&quot;&quot;&quot;Thread module emulating a subset of Java&#39;s threading model.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>sys</span> <span class='key'>as</span> <span class='nam'>_sys</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>thread</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>except</span> <span class='nam'>ImportError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>modules</span><span class='op'>[</span><span class='nam'>__name__</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>raise</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>warnings</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>from</span> <span class='nam'>functools</span> <span class='key'>import</span> <span class='nam'>wraps</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>from</span> <span class='nam'>time</span> <span class='key'>import</span> <span class='nam'>time</span> <span class='key'>as</span> <span class='nam'>_time</span><span class='op'>,</span> <span class='nam'>sleep</span> <span class='key'>as</span> <span class='nam'>_sleep</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>from</span> <span class='nam'>traceback</span> <span class='key'>import</span> <span class='nam'>format_exc</span> <span class='key'>as</span> <span class='nam'>_format_exc</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>from</span> <span class='nam'>collections</span> <span class='key'>import</span> <span class='nam'>deque</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Note regarding PEP 8 compliant aliases</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; This threading model was originally inspired by Java, and inherited</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># the convention of camelCase function and method names from that</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># language. While those names are not in any imminent danger of being</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># deprecated, starting with Python 2.6, the module now provides a</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># PEP 8 compliant alias for any such method name.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Using the new PEP 8 compliant names also facilitates substitution</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># with the multiprocessing module, which doesn&#39;t provide the old</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Java inspired names.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Rename some stuff so &quot;from threading import *&quot; is safe</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>__all__</span> <span class='op'>=</span> <span class='op'>[</span><span class='str'>&#39;activeCount&#39;</span><span class='op'>,</span> <span class='str'>&#39;active_count&#39;</span><span class='op'>,</span> <span class='str'>&#39;Condition&#39;</span><span class='op'>,</span> <span class='str'>&#39;currentThread&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&#39;current_thread&#39;</span><span class='op'>,</span> <span class='str'>&#39;enumerate&#39;</span><span class='op'>,</span> <span class='str'>&#39;Event&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&#39;Lock&#39;</span><span class='op'>,</span> <span class='str'>&#39;RLock&#39;</span><span class='op'>,</span> <span class='str'>&#39;Semaphore&#39;</span><span class='op'>,</span> <span class='str'>&#39;BoundedSemaphore&#39;</span><span class='op'>,</span> <span class='str'>&#39;Thread&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&#39;Timer&#39;</span><span class='op'>,</span> <span class='str'>&#39;setprofile&#39;</span><span class='op'>,</span> <span class='str'>&#39;settrace&#39;</span><span class='op'>,</span> <span class='str'>&#39;local&#39;</span><span class='op'>,</span> <span class='str'>&#39;stack_size&#39;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_start_new_thread</span> <span class='op'>=</span> <span class='nam'>thread</span><span class='op'>.</span><span class='nam'>start_new_thread</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_allocate_lock</span> <span class='op'>=</span> <span class='nam'>thread</span><span class='op'>.</span><span class='nam'>allocate_lock</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_get_ident</span> <span class='op'>=</span> <span class='nam'>thread</span><span class='op'>.</span><span class='nam'>get_ident</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>ThreadError</span> <span class='op'>=</span> <span class='nam'>thread</span><span class='op'>.</span><span class='nam'>error</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>del</span> <span class='nam'>thread</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># sys.exc_clear is used to work around the fact that except blocks</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># don&#39;t fully clear the exception until 3.0.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>warnings</span><span class='op'>.</span><span class='nam'>filterwarnings</span><span class='op'>(</span><span class='str'>&#39;ignore&#39;</span><span class='op'>,</span> <span class='nam'>category</span><span class='op'>=</span><span class='nam'>DeprecationWarning</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>module</span><span class='op'>=</span><span class='str'>&#39;threading&#39;</span><span class='op'>,</span> <span class='nam'>message</span><span class='op'>=</span><span class='str'>&#39;sys.exc_clear&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Debug support (adapted from ihooks.py).</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># All the major classes here derive from _Verbose.&nbsp; We force that to</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># be a new-style class so that all the major classes here are new-style.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># This helps debugging (type(instance) is more revealing for instances</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># of new-style classes).</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_VERBOSE</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>class</span> <span class='nam'>_Verbose</span><span class='op'>(</span><span class='nam'>object</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>62</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>verbose</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>verbose</span> <span class='op'>=</span> <span class='nam'>_VERBOSE</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__verbose</span> <span class='op'>=</span> <span class='nam'>verbose</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_note</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>format</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>66</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__verbose</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>format</span> <span class='op'>=</span> <span class='nam'>format</span> <span class='op'>%</span> <span class='nam'>args</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>format</span> <span class='op'>=</span> <span class='str'>&quot;%s: %s\n&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>current_thread</span><span class='op'>(</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>name</span><span class='op'>,</span> <span class='nam'>format</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>stderr</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>format</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># Disable this when using &quot;python -O&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>class</span> <span class='nam'>_Verbose</span><span class='op'>(</span><span class='nam'>object</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_note</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Support for profile and trace hooks</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_profile_hook</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_trace_hook</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>setprofile</span><span class='op'>(</span><span class='nam'>func</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>global</span> <span class='nam'>_profile_hook</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_profile_hook</span> <span class='op'>=</span> <span class='nam'>func</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>settrace</span><span class='op'>(</span><span class='nam'>func</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>global</span> <span class='nam'>_trace_hook</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>_trace_hook</span> <span class='op'>=</span> <span class='nam'>func</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Synchronization classes</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>Lock</span> <span class='op'>=</span> <span class='nam'>_allocate_lock</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>RLock</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_RLock</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_RLock</span><span class='op'>(</span><span class='nam'>_Verbose</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_Verbose</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span> <span class='op'>=</span> <span class='nam'>_allocate_lock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__repr__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>owner</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&quot;&lt;%s(%s, %d)&gt;&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__class__</span><span class='op'>.</span><span class='nam'>__name__</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>owner</span> <span class='key'>and</span> <span class='nam'>owner</span><span class='op'>.</span><span class='nam'>name</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>acquire</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>blocking</span><span class='op'>=</span><span class='num'>1</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>me</span> <span class='op'>=</span> <span class='nam'>current_thread</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>117</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span> <span class='key'>is</span> <span class='nam'>me</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.acquire(%s): recursive success&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>blocking</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>rc</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='nam'>blocking</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>129</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>rc</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span> <span class='op'>=</span> <span class='nam'>me</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span> <span class='op'>=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.acquire(%s): initial success&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>blocking</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.acquire(%s): failure&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>blocking</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>rc</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__enter__</span> <span class='op'>=</span> <span class='nam'>acquire</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>release</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>136</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>current_thread</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;cannot release un-aquired lock&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span> <span class='op'>=</span> <span class='nam'>count</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span> <span class='op'>-</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>145</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>count</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.release(): final release&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.release(): non-final release&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__exit__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>t</span><span class='op'>,</span> <span class='nam'>v</span><span class='op'>,</span> <span class='nam'>tb</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># Internal methods used by condition variables</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_acquire_restore</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>count_owner</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>count</span><span class='op'>,</span> <span class='nam'>owner</span> <span class='op'>=</span> <span class='nam'>count_owner</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span> <span class='op'>=</span> <span class='nam'>count</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span> <span class='op'>=</span> <span class='nam'>owner</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s._acquire_restore()&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_release_save</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s._release_save()&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>count</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__count</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>owner</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='op'>(</span><span class='nam'>count</span><span class='op'>,</span> <span class='nam'>owner</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_is_owned</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__owner</span> <span class='key'>is</span> <span class='nam'>current_thread</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>Condition</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_Condition</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_Condition</span><span class='op'>(</span><span class='nam'>_Verbose</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>lock</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_Verbose</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>182</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>lock</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>lock</span> <span class='op'>=</span> <span class='nam'>RLock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__lock</span> <span class='op'>=</span> <span class='nam'>lock</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Export the lock&#39;s acquire() and release() methods</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>acquire</span> <span class='op'>=</span> <span class='nam'>lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>release</span> <span class='op'>=</span> <span class='nam'>lock</span><span class='op'>.</span><span class='nam'>release</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># If the lock defines _release_save() and/or _acquire_restore(),</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># these override the default implementations (which just call</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># release() and acquire() on the lock).&nbsp; Ditto for _is_owned().</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_release_save</span> <span class='op'>=</span> <span class='nam'>lock</span><span class='op'>.</span><span class='nam'>_release_save</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>AttributeError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_acquire_restore</span> <span class='op'>=</span> <span class='nam'>lock</span><span class='op'>.</span><span class='nam'>_acquire_restore</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>AttributeError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_is_owned</span> <span class='op'>=</span> <span class='nam'>lock</span><span class='op'>.</span><span class='nam'>_is_owned</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>AttributeError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__waiters</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__enter__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__lock</span><span class='op'>.</span><span class='nam'>__enter__</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__exit__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__lock</span><span class='op'>.</span><span class='nam'>__exit__</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__repr__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&quot;&lt;Condition(%s, %d)&gt;&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__lock</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__waiters</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_release_save</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__lock</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='com'># No state to save</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_acquire_restore</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>x</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='com'># Ignore saved state</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_is_owned</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Return True if lock is owned by current_thread.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># This method is called only if __lock doesn&#39;t have _is_owned().</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>223</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__lock</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>wait</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>timeout</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>230</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_is_owned</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;cannot wait on un-aquired lock&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>waiter</span> <span class='op'>=</span> <span class='nam'>_allocate_lock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>waiter</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__waiters</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>waiter</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>saved_state</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_release_save</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span>&nbsp; &nbsp; <span class='com'># restore state no matter what (e.g., KeyboardInterrupt)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>246</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>timeout</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>waiter</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.wait(): got it&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Balancing act:&nbsp; We can&#39;t afford a pure busy loop, so we</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># have to sleep; but if we sleep the whole timeout time,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># we&#39;ll be unresponsive.&nbsp; The scheme here sleeps very</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># little at first, longer as time goes on, but never longer</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># than 20 times per second (or the timeout time remaining).</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>endtime</span> <span class='op'>=</span> <span class='nam'>_time</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>+</span> <span class='nam'>timeout</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>delay</span> <span class='op'>=</span> <span class='num'>0.0005</span> <span class='com'># 500 us -&gt; initial delay of 1 ms</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>True</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>gotit</span> <span class='op'>=</span> <span class='nam'>waiter</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>gotit</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>remaining</span> <span class='op'>=</span> <span class='nam'>endtime</span> <span class='op'>-</span> <span class='nam'>_time</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>remaining</span> <span class='op'>&lt;=</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>delay</span> <span class='op'>=</span> <span class='nam'>min</span><span class='op'>(</span><span class='nam'>delay</span> <span class='op'>*</span> <span class='num'>2</span><span class='op'>,</span> <span class='nam'>remaining</span><span class='op'>,</span> <span class='num'>.05</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_sleep</span><span class='op'>(</span><span class='nam'>delay</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>gotit</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.wait(%s): timed out&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>timeout</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__waiters</span><span class='op'>.</span><span class='nam'>remove</span><span class='op'>(</span><span class='nam'>waiter</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>ValueError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.wait(%s): got it&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>timeout</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_acquire_restore</span><span class='op'>(</span><span class='nam'>saved_state</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>notify</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>n</span><span class='op'>=</span><span class='num'>1</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>272</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_is_owned</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;cannot notify on un-aquired lock&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>__waiters</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__waiters</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>waiters</span> <span class='op'>=</span> <span class='nam'>__waiters</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>n</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>waiters</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.notify(): no waiters&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.notify(): notifying %d waiter%s&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>n</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>n</span><span class='op'>!=</span><span class='num'>1</span> <span class='key'>and</span> <span class='str'>&quot;s&quot;</span> <span class='key'>or</span> <span class='str'>&quot;&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>waiter</span> <span class='key'>in</span> <span class='nam'>waiters</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>waiter</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>__waiters</span><span class='op'>.</span><span class='nam'>remove</span><span class='op'>(</span><span class='nam'>waiter</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>ValueError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>notifyAll</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>notify</span><span class='op'>(</span><span class='nam'>len</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__waiters</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>notify_all</span> <span class='op'>=</span> <span class='nam'>notifyAll</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>Semaphore</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_Semaphore</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_Semaphore</span><span class='op'>(</span><span class='nam'>_Verbose</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># After Tim Peters&#39; semaphore class, but not quite the same (no maximum)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>value</span><span class='op'>=</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>value</span> <span class='op'>&lt;</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>ValueError</span><span class='op'>(</span><span class='str'>&quot;semaphore initial value must be &gt;= 0&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_Verbose</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span> <span class='op'>=</span> <span class='nam'>Condition</span><span class='op'>(</span><span class='nam'>Lock</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span> <span class='op'>=</span> <span class='nam'>value</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>acquire</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>blocking</span><span class='op'>=</span><span class='num'>1</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>rc</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span> <span class='op'>==</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>blocking</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.acquire(%s): blocked waiting, value=%s&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>blocking</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>wait</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span> <span class='op'>-</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.acquire: success, value=%s&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>rc</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>rc</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__enter__</span> <span class='op'>=</span> <span class='nam'>acquire</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>release</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.release: success, value=%s&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>self</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__value</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>notify</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__exit__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>t</span><span class='op'>,</span> <span class='nam'>v</span><span class='op'>,</span> <span class='nam'>tb</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>BoundedSemaphore</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_BoundedSemaphore</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_BoundedSemaphore</span><span class='op'>(</span><span class='nam'>_Semaphore</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Semaphore that checks that # releases is &lt;= # acquires&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>value</span><span class='op'>=</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_Semaphore</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>value</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_initial_value</span> <span class='op'>=</span> <span class='nam'>value</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>release</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_Semaphore__value</span> <span class='op'>&gt;=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_initial_value</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>ValueError</span><span class='op'>,</span> <span class='str'>&quot;Semaphore released too many times&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_Semaphore</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>Event</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_Event</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_Event</span><span class='op'>(</span><span class='nam'>_Verbose</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># After Tim Peters&#39; event class (without is_posted())</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_Verbose</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span> <span class='op'>=</span> <span class='nam'>Condition</span><span class='op'>(</span><span class='nam'>Lock</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__flag</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>isSet</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__flag</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>is_set</span> <span class='op'>=</span> <span class='nam'>isSet</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>set</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__flag</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>notify_all</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>clear</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__flag</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>wait</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>timeout</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__flag</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>wait</span><span class='op'>(</span><span class='nam'>timeout</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__cond</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Helper to generate new thread names</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_counter</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>_newname</span><span class='op'>(</span><span class='nam'>template</span><span class='op'>=</span><span class='str'>&quot;Thread-%d&quot;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>global</span> <span class='nam'>_counter</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>_counter</span> <span class='op'>=</span> <span class='nam'>_counter</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>template</span> <span class='op'>%</span> <span class='nam'>_counter</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Active thread administration</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_active_limbo_lock</span> <span class='op'>=</span> <span class='nam'>_allocate_lock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_active</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span>&nbsp; &nbsp; <span class='com'># maps thread id to Thread object</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_limbo</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Main class for threads</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>Thread</span><span class='op'>(</span><span class='nam'>_Verbose</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__initialized</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># Need to store a reference to sys.exc_info for printing</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># out exceptions when a thread tries to use a global var. during interp.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># shutdown and thus raises an exception about trying to perform some</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># operation on/with a NoneType</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__exc_info</span> <span class='op'>=</span> <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>exc_info</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># Keep sys.exc_clear too to clear the exception just before</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># allowing .join() to return.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__exc_clear</span> <span class='op'>=</span> <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>exc_clear</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>group</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>target</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>name</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>args</span><span class='op'>=</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>kwargs</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>group</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>,</span> <span class='str'>&quot;group argument must be None for now&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_Verbose</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>verbose</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>430</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>kwargs</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>kwargs</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__target</span> <span class='op'>=</span> <span class='nam'>target</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__name</span> <span class='op'>=</span> <span class='nam'>str</span><span class='op'>(</span><span class='nam'>name</span> <span class='key'>or</span> <span class='nam'>_newname</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__args</span> <span class='op'>=</span> <span class='nam'>args</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__kwargs</span> <span class='op'>=</span> <span class='nam'>kwargs</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__daemonic</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_set_daemon</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__ident</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__started</span> <span class='op'>=</span> <span class='nam'>Event</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stopped</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span> <span class='op'>=</span> <span class='nam'>Condition</span><span class='op'>(</span><span class='nam'>Lock</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># sys.stderr is not stored in the class like</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># sys.exc_info since it can be changed between instances</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stderr</span> <span class='op'>=</span> <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>stderr</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_set_daemon</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Overridden in _MainThread and _DummyThread</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>current_thread</span><span class='op'>(</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>daemon</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__repr__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>,</span> <span class='str'>&quot;Thread.__init__() was not called&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>status</span> <span class='op'>=</span> <span class='str'>&quot;initial&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__started</span><span class='op'>.</span><span class='nam'>is_set</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>status</span> <span class='op'>=</span> <span class='str'>&quot;started&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stopped</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>status</span> <span class='op'>=</span> <span class='str'>&quot;stopped&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__daemonic</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>status</span> <span class='op'>+=</span> <span class='str'>&quot; daemon&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__ident</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>status</span> <span class='op'>+=</span> <span class='str'>&quot; %s&quot;</span> <span class='op'>%</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__ident</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&quot;&lt;%s(%s, %s)&gt;&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__class__</span><span class='op'>.</span><span class='nam'>__name__</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__name</span><span class='op'>,</span> <span class='nam'>status</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>start</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>463</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;thread.__init__() not called&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>465</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__started</span><span class='op'>.</span><span class='nam'>is_set</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;thread already started&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.start(): starting thread&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_limbo</span><span class='op'>[</span><span class='nam'>self</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>self</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_start_new_thread</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__bootstrap</span><span class='op'>,</span> <span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__started</span><span class='op'>.</span><span class='nam'>wait</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>run</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__target</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__target</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Avoid a refcycle if the thread is running a function with</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># an argument that has a member that points to the thread.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__target</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__args</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__kwargs</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__bootstrap</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Wrapper around the real bootstrap code that ignores</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># exceptions during interpreter cleanup.&nbsp; Those typically</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># happen when a daemon thread wakes up at an unfortunate</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># moment, finds the world around it destroyed, and raises some</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># random exception *** while trying to report the exception in</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># __bootstrap_inner() below ***.&nbsp; Those random exceptions</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># don&#39;t help anybody, and they confuse users, so we suppress</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># them.&nbsp; We suppress them only when it appears that the world</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># indeed has already been destroyed, so that exceptions in</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># __bootstrap_inner() during normal business hours are properly</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># reported.&nbsp; Also, we only suppress them for daemonic threads;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># if a non-daemonic encounters this, something else is wrong.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__bootstrap_inner</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__daemonic</span> <span class='key'>and</span> <span class='nam'>_sys</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_set_ident</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__ident</span> <span class='op'>=</span> <span class='nam'>_get_ident</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__bootstrap_inner</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_set_ident</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__started</span><span class='op'>.</span><span class='nam'>set</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active</span><span class='op'>[</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__ident</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>self</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>_limbo</span><span class='op'>[</span><span class='nam'>self</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.__bootstrap(): thread started&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>_trace_hook</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.__bootstrap(): registering trace hook&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>settrace</span><span class='op'>(</span><span class='nam'>_trace_hook</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>_profile_hook</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.__bootstrap(): registering profile hook&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>setprofile</span><span class='op'>(</span><span class='nam'>_profile_hook</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>run</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>SystemExit</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.__bootstrap(): raised SystemExit&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.__bootstrap(): unhandled exception&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># If sys.stderr is no more (most likely from interpreter</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># shutdown) use self.__stderr.&nbsp; Otherwise still use sys (as in</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># _sys) in case sys.stderr was redefined since the creation of</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># self.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>_sys</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>stderr</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='str'>&quot;Exception in thread %s:\n%s\n&quot;</span> <span class='op'>%</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>name</span><span class='op'>,</span> <span class='nam'>_format_exc</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Do the best job possible w/o a huge amt. of code to</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># approximate a traceback (code ideas from</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Lib/traceback.py)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>exc_type</span><span class='op'>,</span> <span class='nam'>exc_value</span><span class='op'>,</span> <span class='nam'>exc_tb</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__exc_info</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span><span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stderr</span><span class='op'>,</span> <span class='op'>(</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;Exception in thread &quot;</span> <span class='op'>+</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>name</span> <span class='op'>+</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot; (most likely raised during interpreter shutdown):&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span><span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stderr</span><span class='op'>,</span> <span class='op'>(</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;Traceback (most recent call last):&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>exc_tb</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span><span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stderr</span><span class='op'>,</span> <span class='op'>(</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&#39;&nbsp; File &quot;%s&quot;, line %s, in %s&#39;</span> <span class='op'>%</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='op'>(</span><span class='nam'>exc_tb</span><span class='op'>.</span><span class='nam'>tb_frame</span><span class='op'>.</span><span class='nam'>f_code</span><span class='op'>.</span><span class='nam'>co_filename</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>exc_tb</span><span class='op'>.</span><span class='nam'>tb_lineno</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>exc_tb</span><span class='op'>.</span><span class='nam'>tb_frame</span><span class='op'>.</span><span class='nam'>f_code</span><span class='op'>.</span><span class='nam'>co_name</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>exc_tb</span> <span class='op'>=</span> <span class='nam'>exc_tb</span><span class='op'>.</span><span class='nam'>tb_next</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span><span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stderr</span><span class='op'>,</span> <span class='op'>(</span><span class='str'>&quot;%s: %s&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>exc_type</span><span class='op'>,</span> <span class='nam'>exc_value</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Make sure that exc_tb gets deleted since it is a memory</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># hog; deleting everything else is just for thoroughness</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>exc_type</span><span class='op'>,</span> <span class='nam'>exc_value</span><span class='op'>,</span> <span class='nam'>exc_tb</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.__bootstrap(): normal return&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Prevent a race in</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># test_threading.test_no_refcycle_through_target when</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># the exception keeps the target alive past when we</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># assert that it&#39;s dead.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__exc_clear</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>with</span> <span class='nam'>_active_limbo_lock</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stop</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We don&#39;t call self.__delete() because it also</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># grabs _active_limbo_lock.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>_active</span><span class='op'>[</span><span class='nam'>_get_ident</span><span class='op'>(</span><span class='op'>)</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__stop</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stopped</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>notify_all</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__delete</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;Remove current thread from the dict of currently running threads.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Notes about running with dummy_thread:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Must take care to not raise an exception if dummy_thread is being</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># used (and thus this module is being used as an instance of</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># dummy_threading).&nbsp; dummy_thread.get_ident() always returns -1 since</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># there is only one thread if dummy_thread is being used.&nbsp; Thus</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># len(_active) is always &lt;= 1 here, and any Thread instance created</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># overwrites the (if any) thread currently registered in _active.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># An instance of _MainThread is always created by &#39;threading&#39;.&nbsp; This</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># gets overwritten the instant an instance of Thread is created; both</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># threads return -1 from dummy_thread.get_ident() and thus have the</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># same key in the dict.&nbsp; So when the _MainThread instance created by</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># &#39;threading&#39; tries to clean itself up when atexit calls this method</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># it gets a KeyError if another Thread instance was created.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># This all means that KeyError from trying to delete something from</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># _active if dummy_threading is being used is a red herring.&nbsp; But</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># since it isn&#39;t if dummy_threading is *not* being used then don&#39;t</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># hide the exception.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>with</span> <span class='nam'>_active_limbo_lock</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>_active</span><span class='op'>[</span><span class='nam'>_get_ident</span><span class='op'>(</span><span class='op'>)</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># There must not be any python code between the previous line</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># and after the lock is released.&nbsp; Otherwise a tracing function</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># could try to acquire the lock again in the same thread, (in</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># current_thread()), and would block.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>KeyError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='str'>&#39;dummy_threading&#39;</span> <span class='key'>not</span> <span class='key'>in</span> <span class='nam'>_sys</span><span class='op'>.</span><span class='nam'>modules</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>join</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>timeout</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>624</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;Thread.__init__() not called&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>626</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__started</span><span class='op'>.</span><span class='nam'>is_set</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;cannot join thread before it is started&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>628</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span> <span class='key'>is</span> <span class='nam'>current_thread</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;cannot join current thread&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stopped</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.join(): waiting until thread stops&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>641</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>timeout</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stopped</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>wait</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.join(): thread stopped&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>deadline</span> <span class='op'>=</span> <span class='nam'>_time</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>+</span> <span class='nam'>timeout</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stopped</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>delay</span> <span class='op'>=</span> <span class='nam'>deadline</span> <span class='op'>-</span> <span class='nam'>_time</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>delay</span> <span class='op'>&lt;=</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.join(): timed out&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>wait</span><span class='op'>(</span><span class='nam'>delay</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s.join(): thread stopped&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__block</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='op'>@</span><span class='nam'>property</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>name</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>,</span> <span class='str'>&quot;Thread.__init__() not called&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__name</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='op'>@</span><span class='nam'>name</span><span class='op'>.</span><span class='nam'>setter</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>name</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>name</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>,</span> <span class='str'>&quot;Thread.__init__() not called&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__name</span> <span class='op'>=</span> <span class='nam'>str</span><span class='op'>(</span><span class='nam'>name</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='op'>@</span><span class='nam'>property</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>ident</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>,</span> <span class='str'>&quot;Thread.__init__() not called&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__ident</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>isAlive</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>,</span> <span class='str'>&quot;Thread.__init__() not called&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__started</span><span class='op'>.</span><span class='nam'>is_set</span><span class='op'>(</span><span class='op'>)</span> <span class='key'>and</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__stopped</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>is_alive</span> <span class='op'>=</span> <span class='nam'>isAlive</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='op'>@</span><span class='nam'>property</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>daemon</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>,</span> <span class='str'>&quot;Thread.__init__() not called&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__daemonic</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='op'>@</span><span class='nam'>daemon</span><span class='op'>.</span><span class='nam'>setter</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>daemon</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>daemonic</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__initialized</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;Thread.__init__() not called&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__started</span><span class='op'>.</span><span class='nam'>is_set</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>RuntimeError</span><span class='op'>(</span><span class='str'>&quot;cannot set daemon status of active thread&quot;</span><span class='op'>)</span><span class='op'>;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__daemonic</span> <span class='op'>=</span> <span class='nam'>daemonic</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>isDaemon</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>daemon</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>setDaemon</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>daemonic</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>daemon</span> <span class='op'>=</span> <span class='nam'>daemonic</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>getName</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>name</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>setName</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>name</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>name</span> <span class='op'>=</span> <span class='nam'>name</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># The timer class was contributed by Itamar Shtull-Trauring</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>Timer</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_Timer</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_Timer</span><span class='op'>(</span><span class='nam'>Thread</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Call a function after a specified number of seconds:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; t = Timer(30.0, f, args=[], kwargs={})</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; t.start()</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; t.cancel() # stop the timer&#39;s action if it&#39;s still waiting</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>interval</span><span class='op'>,</span> <span class='nam'>function</span><span class='op'>,</span> <span class='nam'>args</span><span class='op'>=</span><span class='op'>[</span><span class='op'>]</span><span class='op'>,</span> <span class='nam'>kwargs</span><span class='op'>=</span><span class='op'>{</span><span class='op'>}</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Thread</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>interval</span> <span class='op'>=</span> <span class='nam'>interval</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>function</span> <span class='op'>=</span> <span class='nam'>function</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>args</span> <span class='op'>=</span> <span class='nam'>args</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>kwargs</span> <span class='op'>=</span> <span class='nam'>kwargs</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>finished</span> <span class='op'>=</span> <span class='nam'>Event</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>cancel</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Stop the timer if it hasn&#39;t finished yet&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>finished</span><span class='op'>.</span><span class='nam'>set</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>run</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>finished</span><span class='op'>.</span><span class='nam'>wait</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>interval</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>finished</span><span class='op'>.</span><span class='nam'>is_set</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>function</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>finished</span><span class='op'>.</span><span class='nam'>set</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Special thread class to represent the main thread</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># This is garbage collected through an exit handler</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_MainThread</span><span class='op'>(</span><span class='nam'>Thread</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Thread</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>name</span><span class='op'>=</span><span class='str'>&quot;MainThread&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_Thread__started</span><span class='op'>.</span><span class='nam'>set</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_set_ident</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active</span><span class='op'>[</span><span class='nam'>_get_ident</span><span class='op'>(</span><span class='op'>)</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>self</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_set_daemon</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_exitfunc</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_Thread__stop</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>t</span> <span class='op'>=</span> <span class='nam'>_pickSomeNonDaemonThread</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>t</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s: waiting for other threads&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>t</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>t</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>t</span> <span class='op'>=</span> <span class='nam'>_pickSomeNonDaemonThread</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>__debug__</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;%s: exiting&quot;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_Thread__delete</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>_pickSomeNonDaemonThread</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>t</span> <span class='key'>in</span> <span class='nam'>enumerate</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>t</span><span class='op'>.</span><span class='nam'>daemon</span> <span class='key'>and</span> <span class='nam'>t</span><span class='op'>.</span><span class='nam'>is_alive</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>t</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Dummy thread class to represent threads not started here.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># These aren&#39;t garbage collected when they die, nor can they be waited for.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># If they invoke anything in threading.py that calls current_thread(), they</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># leave an entry in the _active dict forever after.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Their purpose is to return *something* from current_thread().</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># They are marked as daemon threads so we won&#39;t wait for them</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># when we exit (conform previous semantics).</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_DummyThread</span><span class='op'>(</span><span class='nam'>Thread</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Thread</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>name</span><span class='op'>=</span><span class='nam'>_newname</span><span class='op'>(</span><span class='str'>&quot;Dummy-%d&quot;</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Thread.__block consumes an OS-level locking primitive, which</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># can never be used by a _DummyThread.&nbsp; Since a _DummyThread</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># instance is immortal, that&#39;s bad, so release this resource.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_Thread__block</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_Thread__started</span><span class='op'>.</span><span class='nam'>set</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_set_ident</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active</span><span class='op'>[</span><span class='nam'>_get_ident</span><span class='op'>(</span><span class='op'>)</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>self</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_set_daemon</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>join</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>timeout</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>False</span><span class='op'>,</span> <span class='str'>&quot;cannot join a dummy thread&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Global API functions</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>currentThread</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_active</span><span class='op'>[</span><span class='nam'>_get_ident</span><span class='op'>(</span><span class='op'>)</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>KeyError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>##print &quot;current_thread(): no current thread for&quot;, _get_ident()</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_DummyThread</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>current_thread</span> <span class='op'>=</span> <span class='nam'>currentThread</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>activeCount</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>count</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>_active</span><span class='op'>)</span> <span class='op'>+</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>_limbo</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>count</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>active_count</span> <span class='op'>=</span> <span class='nam'>activeCount</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>enumerate</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>active</span> <span class='op'>=</span> <span class='nam'>_active</span><span class='op'>.</span><span class='nam'>values</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>+</span> <span class='nam'>_limbo</span><span class='op'>.</span><span class='nam'>values</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>active</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>from</span> <span class='nam'>thread</span> <span class='key'>import</span> <span class='nam'>stack_size</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Create the main thread object,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># and make it available for the interpreter</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># (Py_Main) as threading._shutdown.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_shutdown</span> <span class='op'>=</span> <span class='nam'>_MainThread</span><span class='op'>(</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>_exitfunc</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># get thread-local implementation, either from the thread</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># module, or from the python fallback</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>thread</span> <span class='key'>import</span> <span class='nam'>_local</span> <span class='key'>as</span> <span class='nam'>local</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>except</span> <span class='nam'>ImportError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>_threading_local</span> <span class='key'>import</span> <span class='nam'>local</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>_after_fork</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># This function is called by Python/ceval.c:PyEval_ReInitThreads which</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># is called from PyOS_AfterFork.&nbsp; Here we cleanup threading module state</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># that should not exist after a fork.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># Reset _active_limbo_lock, in case we forked while the lock was held</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># by another (non-forked) thread.&nbsp; http://bugs.python.org/issue874900</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>global</span> <span class='nam'>_active_limbo_lock</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_active_limbo_lock</span> <span class='op'>=</span> <span class='nam'>_allocate_lock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># fork() only copied the current thread; clear references to others.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>new_active</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>current</span> <span class='op'>=</span> <span class='nam'>current_thread</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>with</span> <span class='nam'>_active_limbo_lock</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>thread</span> <span class='key'>in</span> <span class='nam'>_active</span><span class='op'>.</span><span class='nam'>itervalues</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>thread</span> <span class='key'>is</span> <span class='nam'>current</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># There is only one active thread. We reset the ident to</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># its new value since it can have changed.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>ident</span> <span class='op'>=</span> <span class='nam'>_get_ident</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>thread</span><span class='op'>.</span><span class='nam'>_Thread__ident</span> <span class='op'>=</span> <span class='nam'>ident</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>new_active</span><span class='op'>[</span><span class='nam'>ident</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>thread</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># All the others are already stopped.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We don&#39;t call _Thread__stop() because it tries to acquire</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># thread._Thread__block which could also have been held while</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># we forked.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>thread</span><span class='op'>.</span><span class='nam'>_Thread__stopped</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_limbo</span><span class='op'>.</span><span class='nam'>clear</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active</span><span class='op'>.</span><span class='nam'>clear</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_active</span><span class='op'>.</span><span class='nam'>update</span><span class='op'>(</span><span class='nam'>new_active</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>_active</span><span class='op'>)</span> <span class='op'>==</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Self-test code</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>_test</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>class</span> <span class='nam'>BoundedQueue</span><span class='op'>(</span><span class='nam'>_Verbose</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>limit</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_Verbose</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>mon</span> <span class='op'>=</span> <span class='nam'>RLock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>rc</span> <span class='op'>=</span> <span class='nam'>Condition</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>mon</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>wc</span> <span class='op'>=</span> <span class='nam'>Condition</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>mon</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>limit</span> <span class='op'>=</span> <span class='nam'>limit</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span> <span class='op'>=</span> <span class='nam'>deque</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>put</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>item</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>mon</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span><span class='op'>)</span> <span class='op'>&gt;=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>limit</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;put(%s): queue full&quot;</span><span class='op'>,</span> <span class='nam'>item</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>wc</span><span class='op'>.</span><span class='nam'>wait</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>item</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;put(%s): appended, length now %d&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>item</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>rc</span><span class='op'>.</span><span class='nam'>notify</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>mon</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>get</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>mon</span><span class='op'>.</span><span class='nam'>acquire</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;get(): queue empty&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>rc</span><span class='op'>.</span><span class='nam'>wait</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>item</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span><span class='op'>.</span><span class='nam'>popleft</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_note</span><span class='op'>(</span><span class='str'>&quot;get(): got %s, %d left&quot;</span><span class='op'>,</span> <span class='nam'>item</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>wc</span><span class='op'>.</span><span class='nam'>notify</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>mon</span><span class='op'>.</span><span class='nam'>release</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>item</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>class</span> <span class='nam'>ProducerThread</span><span class='op'>(</span><span class='nam'>Thread</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>queue</span><span class='op'>,</span> <span class='nam'>quota</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Thread</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>name</span><span class='op'>=</span><span class='str'>&quot;Producer&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span> <span class='op'>=</span> <span class='nam'>queue</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>quota</span> <span class='op'>=</span> <span class='nam'>quota</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>run</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>random</span> <span class='key'>import</span> <span class='nam'>random</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>counter</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>counter</span> <span class='op'>&lt;</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>quota</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>counter</span> <span class='op'>=</span> <span class='nam'>counter</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span><span class='op'>.</span><span class='nam'>put</span><span class='op'>(</span><span class='str'>&quot;%s.%d&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>name</span><span class='op'>,</span> <span class='nam'>counter</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_sleep</span><span class='op'>(</span><span class='nam'>random</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>*</span> <span class='num'>0.00001</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>class</span> <span class='nam'>ConsumerThread</span><span class='op'>(</span><span class='nam'>Thread</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>queue</span><span class='op'>,</span> <span class='nam'>count</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Thread</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>name</span><span class='op'>=</span><span class='str'>&quot;Consumer&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span> <span class='op'>=</span> <span class='nam'>queue</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>count</span> <span class='op'>=</span> <span class='nam'>count</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>run</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>count</span> <span class='op'>&gt;</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>item</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>queue</span><span class='op'>.</span><span class='nam'>get</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='nam'>item</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>count</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>count</span> <span class='op'>-</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>NP</span> <span class='op'>=</span> <span class='num'>3</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>QL</span> <span class='op'>=</span> <span class='num'>4</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>NI</span> <span class='op'>=</span> <span class='num'>5</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>Q</span> <span class='op'>=</span> <span class='nam'>BoundedQueue</span><span class='op'>(</span><span class='nam'>QL</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>P</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>i</span> <span class='key'>in</span> <span class='nam'>range</span><span class='op'>(</span><span class='nam'>NP</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>t</span> <span class='op'>=</span> <span class='nam'>ProducerThread</span><span class='op'>(</span><span class='nam'>Q</span><span class='op'>,</span> <span class='nam'>NI</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>t</span><span class='op'>.</span><span class='nam'>name</span> <span class='op'>=</span> <span class='op'>(</span><span class='str'>&quot;Producer-%d&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>i</span><span class='op'>+</span><span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>P</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>t</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>C</span> <span class='op'>=</span> <span class='nam'>ConsumerThread</span><span class='op'>(</span><span class='nam'>Q</span><span class='op'>,</span> <span class='nam'>NI</span><span class='op'>*</span><span class='nam'>NP</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>t</span> <span class='key'>in</span> <span class='nam'>P</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>t</span><span class='op'>.</span><span class='nam'>start</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_sleep</span><span class='op'>(</span><span class='num'>0.000001</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>C</span><span class='op'>.</span><span class='nam'>start</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>t</span> <span class='key'>in</span> <span class='nam'>P</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>t</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>C</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>if</span> <span class='nam'>__name__</span> <span class='op'>==</span> <span class='str'>&#39;__main__&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_test</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
    
</td>
</tr>
</table>
</div>

</body>
</html>
